package com.zq.designpaterns.other.frontcontroller;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2021/01/28  10:30
 * 修改日期：
 * 描    述：
 * 修订历史：
 * ================================================
 */
public class FrontController {
    private final Dispatcher dispatcher;

    public FrontController() {
        dispatcher = new Dispatcher();
    }

    private boolean isAuthenticUser() {
        System.out.println("User is authenticate successfully!");
        return true;
    }

    private void trackRequest(String request) {
        System.out.println("page request:" + request);
    }

    public void dispatchRequest(String request) {
        // 记录每一个请求
        trackRequest(request);
        // 身份验证
        if (isAuthenticUser()) {
            dispatcher.dispatch(request);
        }
    }
}
